﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LiveCharts;
using LiveCharts.Wpf;

namespace CentralMonitoring
{
    public partial class testPieChartFrm : Form
    {
        public testPieChartFrm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            pieChart1.Series.Clear();
            Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0}({1:P})", chartPoint.Y, chartPoint.Participation);
            SeriesCollection piechartData = new SeriesCollection
             {
                 new PieSeries
                 {
                     Title="First Item",
                     Values=new ChartValues<double> {25},
                     DataLabels=true,
                     LabelPoint=labelPoint,
                     Fill = System.Windows.Media.Brushes.Black
                 },
                 new PieSeries
                 {
                     Title="Second Item",
                     Values=new ChartValues<double> {25},
                     DataLabels=true,
                     LabelPoint=labelPoint,
                     Fill=System.Windows.Media.Brushes.Green,
                     PushOut=15
                 },
                 new PieSeries
                 {
                     Title="Third Item",
                     Values=new ChartValues<double> {25},
                     DataLabels=true,
                     LabelPoint=labelPoint,
                     Fill = System.Windows.Media.Brushes.Pink
                 }
             };
            piechartData.Add(
                new PieSeries
                {
                    Title = "Fourth Item",
                    Values = new ChartValues<double> { 25 },
                    DataLabels = true,
                    LabelPoint = labelPoint,
                    Fill = System.Windows.Media.Brushes.Gray
                });
            pieChart1.Series = piechartData;
            pieChart1.LegendLocation = LegendLocation.Right;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);

            // Define the collection of Values to display in the Pie Chart
            pieChart1.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title = "USA",
                    Values = new ChartValues<double> {6450},
                    DataLabels = true,
                    LabelPoint = labelPoint,

                },
                new PieSeries
                {
                    Title = "Russia",
                    Values = new ChartValues<double> {6850},
                    DataLabels = true,
                    LabelPoint = labelPoint
                },
                new PieSeries
                {
                    Title = "United Kingdom",
                    Values = new ChartValues<double> {215},
                    DataLabels = true,
                    LabelPoint = labelPoint
                },
                new PieSeries
                {
                    Title = "France",
                    Values = new ChartValues<double> {300},
                    DataLabels = true,
                    LabelPoint = labelPoint
                },
                new PieSeries
                {
                    Title = "China",
                    Values = new ChartValues<double> {280},
                    DataLabels = true,
                    LabelPoint = labelPoint
                }
            };

            // Set the legend location to appear in the bottom of the chart
            pieChart1.LegendLocation = LegendLocation.Bottom;
        }
    }
}
